 function getContent(p, para) {
				var APIUrl;

				jQuery('#body-wrapper').showLoading();
				$(".current").removeClass("current");
                $("#MainOSDetail_freeMenu").addClass("current");
                $(".default-tab").addClass("current");

				/*if (para == "30")
				{
					var startDate = new Date()
					startDate.setDate(startDate.getDate()-30);
					para = "?staDate="+ startDate.getFullYear()+ "/" + (startDate.getMonth()+1)+ "/" + startDate.getDate() +"&pd=30";
					$("#"+p+"Date30").addClass("current");
				}
                
                if (para == "31")
				{
					var startDate = new Date()
					startDate.setDate(startDate.getDate()-30);
					para = "?staDate="+ startDate.getFullYear()+ "/" + (startDate.getMonth()+1)+ "/" + startDate.getDate() +"&pd=30";
					$("#"+p+"Date30").addClass("current");
				}*/
                
           


			
					APIUrl = "/client/mainAnalytics"+para;
					$.ajax({
						type: "GET",
						url: APIUrl,
						dataType : "jsonp",
						jsonnp: "callback",
						success: ly123
					});
				
				
                
 
                
                
			}
            
function freewapcd(){
    
var sd = document.getElementById("freewaply").options[document.getElementById("freewaply").selectedIndex].value;
updatePresetDataRange('MainOSDetail_freeDate',sd);

}
            
            
            //自选时间区间更新
function updateDateRange(div) {
	//var startDate = new Date();
	//var endDate = new Date();
    
    
    
    var startDate = $("#MainOSDetail_freeStartDate").val();
	var endDate = $("#MainOSDetail_freeEndDate").val();
    
    //alert(startDate);

	/*startDate.setFullYear(($("#"+div+"StartDate").val()).substring(0,4), ($("#"+div+"StartDate").val()).substring(5,7)-1,($("#"+div+"StartDate").val()).substring(8,10));
	endDate.setFullYear(($("#"+div+"EndDate").val()).substring(0,4), ($("#"+div+"EndDate").val()).substring(5,7)-1,($("#"+div+"EndDate").val()).substring(8,10));*/

	//days = parseInt((endDate - startDate)/1000/60/60/24)+1;
    
    var start = new Date();
    var end = new Date();

			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

	if (days > 0)
	{
		getContent(page, "?staDate="+startDate+"&pd="+days);
	}
	else 
		alert("选择区间不对");

	$("."+div+"Date").removeClass("current");

}

//预设时间区域 周、月、季、年、全部
function updatePresetDataRange(linkDiv, days) {
	if (days == "All")
		getContent(page, "");
	else {
		var startDate = new Date()
		startDate.setDate(startDate.getDate()-days);
		getContent(page, "?staDate="+ startDate.getFullYear()+ "/" + (startDate.getMonth()+1)+ "/" + startDate.getDate() +"&pd="+days);
	}
	$("."+linkDiv).removeClass("current");
	$("#"+linkDiv+days).addClass("current");
}
            
            function loadData(data, startDateID, endDateID) {
	var uv, vv, pv, nu, nr, su;
	osArr = new Array();
	osArr = ["FreeWap ", "iOS Pad", "Android Phone", "Android Pad", "WP7 Phone", "FreeWap "];
	detailArr = new Array();
	for(osi=0; osi<6; osi++) {
		detailArr[osi] = new Array();
		detailArr[osi][0] = new Array();
		detailArr[osi][1] = new Array();
		detailArr[osi][2] = new Array();
		detailArr[osi][3] = new Array();
		detailArr[osi][4] = new Array();
		detailArr[osi][5] = new Array();
		detailArr[osi][6] = new Array();
		detailArr[osi][7] = new Array();
	}
	dateArr = new Array();

	if (data.items.length > 0)
	{
		$(data.items).each(function(i, value){
			var myDate=new Date()

			year = value["year"];
			month = value["month"];
			day = value["day"];
			
			if (i == 0)
			{
				$("#"+startDateID).val(year+"/"+month+"/"+day);
			}

			myDate.setFullYear(year,month-1,day);
			dateArr.push(year + "/" + month + "/" + day);

			details = value["data"];
			$(details).each(function(l, dvalue){
				os = dvalue["os"];
				type = dvalue["type"];
				uv = dvalue["uv"]; //每日使用设备数
				pv = dvalue["pv"]; //页面访问量
				vv = dvalue["vv"]; //播放总量
				nu = dvalue["nu"]; //新增设备数
				nr = dvalue["nr"]; //注册用户数
				su = dvalue["su"]; //成功上传量

				if (typeof(dvalue["uv"])=="undefined")
					uv = 0;
				if (typeof(dvalue["vv"])=="undefined")
					vv = 0;
				if (typeof(dvalue["pv"])=="undefined")
					pv = 0;
				if (typeof(dvalue["nu"])=="undefined")
					nu = 0;
				if (typeof(dvalue["nr"])=="undefined")
					nr = 0;
				if (typeof(dvalue["su"])=="undefined")
					su = 0;			


				osi = in_array(os+" "+type, osArr);
				if(osi == -1) {
					osArr.push(os+" "+type);
					osi=osArr.length-1;
					detailArr[osi] = new Array();
					detailArr[osi][0] = new Array();
					detailArr[osi][1] = new Array();
					detailArr[osi][2] = new Array();
					detailArr[osi][3] = new Array();
					detailArr[osi][4] = new Array();
					detailArr[osi][5] = new Array();
					detailArr[osi][6] = new Array();
					detailArr[osi][7] = new Array();
				}

				if(dateArr.length-detailArr[osi][0].length > 1) {
					var size = dateArr.length-detailArr[osi][0].length;
					for(l=1; l<size; l++) {
						detailArr[osi][0].push(0);
						detailArr[osi][1].push(0);
						detailArr[osi][2].push(0);
						detailArr[osi][3].push(0);
						detailArr[osi][4].push(0);
						detailArr[osi][5].push(0);
						detailArr[osi][7].push(0);
					}
				}


				detailArr[osi][0].push(vv);
				detailArr[osi][1].push(uv);
				detailArr[osi][2].push(pv);
				detailArr[osi][3].push(nu);
				detailArr[osi][4].push(nr);
				detailArr[osi][5].push(su);
				if (uv == 0 || vv == 0)
					detailArr[osi][7].push(0);
				else
					detailArr[osi][7].push(parseFloat((vv/uv).toFixed(2)));
				
			});
		});		
		$("#"+endDateID).val(year+"/"+month+"/"+day);
	}
	else {
		alert("选择的时间区间内无数据");	
		//$("#"+startDateID).val("");
		//$("#"+endDateID).val("");
	}
}
            
            
            function loadMainOSDetail_free(data) {
                var MainOSDetailTab = "";
var valueTypes = new Array("播放数(VV)", "使用设备数(UV)", "页面访问量(PV)", "", "", "", "","VV/UV");
	loadData(data, 'MainOSDetail_freeStartDate', 'MainOSDetail_freeEndDate');
	if(data.items.length > 0) {
		genMainOSDetail_freeTab();
		genDetailTable("MainOSDetail_freeTable", valueTypes, dateArr, detailArr, 0, 0);
		genDetailLineChart("MainOSDetail_freeLine",osArr[5]+"趋势图", dateArr, valueTypes, detailArr, 0, $("#MainOSDetail_freeStartDate").val().replace(/\//g, "-") + " 至 " + $("#MainOSDetail_freeEndDate").val().replace(/\//g, "-"));
		changeChartType('MainOSDetail_free', 'Line');
	//	$("#MainOSDetailLineTab").addClass("selbitem");
		$(".bitem").removeClass("selbitem");
		$("#mainOSDetailTab0").addClass("selbitem");	
		$(".tab-content").show();
	}
	else {
		$(".tab-content").hide();	
	}

	jQuery('#body-wrapper').hideLoading();	
}

function genMainOSDetail_freeTab() {
	MainOSDetailTab = ""; 

	$.each(osArr, function(l, os) {
		if (l == 5)
			MainOSDetailTab += "<div id=\"mainOSDetail_freeTab"+ l +"\" onclick=\"changeMainOSDetail_freeType("+ l +")\" class=\"bitem\">总览</div>";
		//else
		//	MainOSDetailTab += "<div id=\"mainOSDetail_freeTab"+ l +"\" onclick=\"changeMainOSDetail_freeType("+ l +")\" class=\"bitem\">"+os+"</div>";
	});
    
    //alert(MainOSDetailTab);
	
	$("#MainOSDetail_freeTab").html(MainOSDetailTab);


}


function changeMainOSDetail_freeType(typeValue) {
	genDetailTable("MainOSDetail_freeTable", valueTypes, dateArr, detailArr, typeValue, 0);
	genDetailLineChart("MainOSDetail_freeLine",osArr[typeValue]+"趋势图", dateArr, valueTypes, detailArr, typeValue, $("#MainOSDetail_freeStartDate").val().replace(/\//g, "-") + " 至 " + $("#MainOSDetail_freeEndDate").val().replace(/\//g, "-"));
	$(".selbitem").removeClass("selbitem");
	$("#mainOSDetail_freeTab"+typeValue).addClass("selbitem");			
	changeChartType('MainOSDetail_free', 'Line');
    getCSVData_save("MainOSDetail_freeTable");	

}
